package projeto;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int gender = babyGender(sc);
		List<BabyName> mom = parentsChoices(0, createList(gender), sc);
		List<BabyName> dad = parentsChoices(1, createList(gender), sc);
		List<BabyName> ultimate = new ArrayList<BabyName>();
		GradeComparator comparator = new GradeComparator();
		
		for (int j = 0; j < mom.size(); j ++){
			if (comparator.compare(mom.get(j), dad.get(j)) == 0 && dad.get(j).getGrade() != 0){
				ultimate.add(mom.get(j));
			}
		}
	
		Collections.sort(ultimate, Collections.reverseOrder(new GradeComparator()));
		for (BabyName baby : ultimate){
			System.out.println(baby.getName() + " " + baby.getGrade());
		}
	}
	
	public static int babyGender(Scanner sc){
		System.out.println("Boy(0) or Girl(1)?");
		int gender = sc.nextInt();
		return gender;
	}
	
	public static List<BabyName> createList(int gender){
		FileReader opener = new FileReader();
		if (gender == 0){
			try{
				opener.openFile("boys.txt");
			}
			catch (Exception e){
				System.out.println(e.getMessage());
			}
		}
		else if (gender == 1){
			try{
				opener.openFile("girls.txt");
			}
			catch (Exception e){
				System.out.println(e.getMessage());
			}
		}
		return opener.getNames();
	}
	
	public static List<BabyName> parentsChoices(int number, List<BabyName> names, Scanner sc){
		int grade;
		String menu = "Name grade?\n2: Awesome!\n1: All right...\n0: No way!";
		if (number == 0){
			System.out.println("Mommy's turn");	
		}
		else{
			System.out.println("Daddy's turn");
		}
		for (BabyName name : names){
			System.out.println(name.getName());
			System.out.println(menu);
			grade = sc.nextInt();
			name.setGrade(grade);
		}
		return names;		
	}
}

